package project.menu;

import java.util.ArrayList;

import project.menu.garagemenu.CreatorGarage;
import project.menu.garagemenu.ListFreeGarage;
import project.menu.garagemenu.NextFreeDate;
import project.menu.garagemenu.NumberFreePlacesOnDate;
import project.menu.garagemenu.RemoverGarage;
import project.menu.mainmenu.ExitItem;
import project.menu.mainmenu.MainMenu;
import project.menu.mainmenu.ResaveData;
import project.menu.mainmenu.WorkerWithGarage;
import project.menu.mainmenu.WorkerWithMaster;
import project.menu.mainmenu.WorkerWithOrder;
import project.menu.mastermenu.CreatorMaster;
import project.menu.mastermenu.ListMasters;
import project.menu.mastermenu.MasterByOrder;
import project.menu.mastermenu.RemoverMaster;
import project.menu.mastermenu.listmenu.MastersByEmployment;
import project.menu.mastermenu.listmenu.MastersByName;
import project.menu.ordermenu.CreatorOrder;
import project.menu.ordermenu.MarkerOrder;
import project.menu.ordermenu.OffsetOrdersDeadlineDate;
import project.menu.ordermenu.OrderByMaster;
import project.menu.ordermenu.OrdersList;
import project.menu.ordermenu.listallorders.AllOrdersByBeginingDate;
import project.menu.ordermenu.listallorders.AllOrdersByDeadlineDate;
import project.menu.ordermenu.listallorders.AllOrdersByFillingDate;
import project.menu.ordermenu.listallorders.AllOrdersByPrice;
import project.menu.ordermenu.listallorders.ListAllOrders;
import project.menu.ordermenu.listcanceledorders.CanceledOrdersByBeginingDate;
import project.menu.ordermenu.listcanceledorders.CanceledOrdersByDeadlineDate;
import project.menu.ordermenu.listcanceledorders.CanceledOrdersByFillingDate;
import project.menu.ordermenu.listcanceledorders.CanceledOrdersByPrice;
import project.menu.ordermenu.listcanceledorders.ListCanceledOrders;
import project.menu.ordermenu.listdeletedorders.DeletedIOrdersByBeginingDate;
import project.menu.ordermenu.listdeletedorders.DeletedOrdersByDeadlineDate;
import project.menu.ordermenu.listdeletedorders.DeletedOrdersByFillingDate;
import project.menu.ordermenu.listdeletedorders.DeletedOrdersByPrice;
import project.menu.ordermenu.listdeletedorders.ListDeletedOrders;
import project.menu.ordermenu.listmadedorders.ListMadedOrders;
import project.menu.ordermenu.listmadedorders.MadedOrdersByBeginingDate;
import project.menu.ordermenu.listmadedorders.MadedOrdersByDeadlineDate;
import project.menu.ordermenu.listmadedorders.MadedOrdersByFillingDate;
import project.menu.ordermenu.listmadedorders.MadedOrdersByPrice;
import project.menu.ordermenu.listmadingorders.ListMadingOrders;
import project.menu.ordermenu.listmadingorders.MadingOrdersByBeginingDate;
import project.menu.ordermenu.listmadingorders.MadingOrdersByDeadlineDate;
import project.menu.ordermenu.listmadingorders.MadingOrdersByFillingDate;
import project.menu.ordermenu.listmadingorders.MadingOrdersByPrice;
import project.menu.ordermenu.markerorder.OrderCanceledStatus;
import project.menu.ordermenu.markerorder.OrderDeletedStatus;
import project.menu.ordermenu.markerorder.OrderMadedStatus;

public class Builder {

	private static ArrayList<IMenuItem> mainMenu= new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> garageMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> sortMastersMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> masterMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> sortAllOrdersMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> sortCanceledOrdersMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> sortDeletedOrdersMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> sortMadedOrdersMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> sortMadingOrdersMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> getOrderListMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> markOrderMenu = new ArrayList<IMenuItem>();
	private static ArrayList<IMenuItem> orderMenu = new ArrayList<IMenuItem>();
	
	private static Back backInMainMenu = new Back();
	private static Back backInMasterMenu = new Back();
	private static Back backInOrderMenu = new Back();
	private static Back backInAllOrderMenu = new Back();
	
	
	private static final IMenu  GARAGE_MENU= new Menu();
	private static final IMenu  MASTER_MENU= new Menu();
	private static final IMenu  SORTED_MASTERS_MENU= new Menu();
	private static final IMenu  ORDER_MENU= new Menu();
	private static final IMenu  ORDER_LIST_MENU= new Menu();
	private static final IMenu  ALL_ORDERS_MENU= new Menu();
	private static final IMenu  CANCELED_ORDERS_MENU= new Menu();
	private static final IMenu  DELETED_ORDERS_MENU= new Menu();
	private static final IMenu  MADED_ORDERS_MENU= new Menu();
	private static final IMenu  MADING_ORDERS_MENU= new Menu();
	private static final IMenu  ORDER_STATUS_MENU= new Menu();

	
	public static void build() {
		backInMainMenu.setMenu(MainMenu.MAINMENU);
		
		
	// create garage menu
		garageMenu.add(new ListFreeGarage());
		garageMenu.add(new NumberFreePlacesOnDate());
		garageMenu.add(new NextFreeDate());
		garageMenu.add(new CreatorGarage());
		garageMenu.add(new RemoverGarage());
		garageMenu.add(backInMainMenu);
		GARAGE_MENU.setMenu(garageMenu);
		WorkerWithGarage.setMenu(GARAGE_MENU);
		ListFreeGarage.setSubmenu(GARAGE_MENU);
		NumberFreePlacesOnDate.setSubmenu(GARAGE_MENU);
		NextFreeDate.setSubmenu(GARAGE_MENU);
		CreatorGarage.setSubmenu(GARAGE_MENU);
		RemoverGarage.setSubmenu(GARAGE_MENU);
		
		

		
		// create sort submenu
		
		backInMasterMenu.setMenu(MASTER_MENU);
		sortMastersMenu.add(new MastersByName());
		sortMastersMenu.add(new MastersByEmployment());
		sortMastersMenu.add(backInMasterMenu);
		SORTED_MASTERS_MENU.setMenu(sortMastersMenu);
		ListMasters.setMenu(SORTED_MASTERS_MENU);
		MastersByName.setSubmenu(SORTED_MASTERS_MENU);
		MastersByEmployment.setSubmenu(SORTED_MASTERS_MENU);
		// create master menu
		 
		
		masterMenu.add(new ListMasters());
		masterMenu.add(new MasterByOrder());
		masterMenu.add(new CreatorMaster());
		masterMenu.add(new RemoverMaster());
		masterMenu.add(backInMainMenu);
		MASTER_MENU.setMenu(masterMenu);
		WorkerWithMaster.setMenu(MASTER_MENU);
		CreatorMaster.setSubmenu(MASTER_MENU);
		RemoverMaster.setSubmenu(MASTER_MENU);
		MasterByOrder.setSubmenu(MASTER_MENU);
		
		
		
	// create orders menu
		backInAllOrderMenu.setMenu(ORDER_LIST_MENU);
		backInOrderMenu.setMenu(ORDER_MENU);
			// create sortallordersby_menu
		
			sortAllOrdersMenu.add(new AllOrdersByFillingDate());
			sortAllOrdersMenu.add(new AllOrdersByBeginingDate());
			sortAllOrdersMenu.add(new AllOrdersByDeadlineDate());
			sortAllOrdersMenu.add(new AllOrdersByPrice());
			sortAllOrdersMenu.add(backInAllOrderMenu);
			ALL_ORDERS_MENU.setMenu(sortAllOrdersMenu);
			ListAllOrders.setMenu(ALL_ORDERS_MENU);
			AllOrdersByFillingDate.setMenu(ALL_ORDERS_MENU);
			AllOrdersByBeginingDate.setMenu(ALL_ORDERS_MENU);
			AllOrdersByDeadlineDate.setMenu(ALL_ORDERS_MENU);
			AllOrdersByPrice.setMenu(ALL_ORDERS_MENU);
	
			// create sortcanceledordersby_menu
			sortCanceledOrdersMenu.add(new CanceledOrdersByFillingDate());
			sortCanceledOrdersMenu.add(new CanceledOrdersByBeginingDate());
			sortCanceledOrdersMenu.add(new CanceledOrdersByDeadlineDate());
			sortCanceledOrdersMenu.add(new CanceledOrdersByPrice());
			sortCanceledOrdersMenu.add(backInAllOrderMenu);
			CANCELED_ORDERS_MENU
					.setMenu(sortCanceledOrdersMenu);
			ListCanceledOrders.setMenu(CANCELED_ORDERS_MENU);
			CanceledOrdersByFillingDate.setMenu(CANCELED_ORDERS_MENU);
			CanceledOrdersByBeginingDate.setMenu(CANCELED_ORDERS_MENU);
			CanceledOrdersByDeadlineDate.setMenu(CANCELED_ORDERS_MENU);
			CanceledOrdersByPrice.setMenu(CANCELED_ORDERS_MENU);			
			
	
			// create sortdeletedordersby_menu
			sortDeletedOrdersMenu.add(new DeletedOrdersByFillingDate());
			sortDeletedOrdersMenu.add(new DeletedIOrdersByBeginingDate());
			sortDeletedOrdersMenu.add(new DeletedOrdersByDeadlineDate());
			sortDeletedOrdersMenu.add(new DeletedOrdersByPrice());
			sortDeletedOrdersMenu.add(backInAllOrderMenu);
			DELETED_ORDERS_MENU
					.setMenu(sortDeletedOrdersMenu);
			ListDeletedOrders.setMenu(DELETED_ORDERS_MENU);
			DeletedOrdersByFillingDate.setMenu(DELETED_ORDERS_MENU);
			DeletedIOrdersByBeginingDate.setMenu(DELETED_ORDERS_MENU);
			DeletedOrdersByDeadlineDate.setMenu(DELETED_ORDERS_MENU);
			DeletedOrdersByPrice.setMenu(DELETED_ORDERS_MENU);
			
	
			// create sortmadedordersby_menu
			sortMadedOrdersMenu.add(new MadedOrdersByFillingDate());
			sortMadedOrdersMenu.add(new MadedOrdersByBeginingDate());
			sortMadedOrdersMenu.add(new MadedOrdersByDeadlineDate());
			sortMadedOrdersMenu.add(new MadedOrdersByPrice());
			sortMadedOrdersMenu.add(backInAllOrderMenu);
			MADED_ORDERS_MENU.setMenu(sortMadedOrdersMenu);
			ListMadedOrders.setMenu(MADED_ORDERS_MENU);
			MadedOrdersByFillingDate.setMenu(MADED_ORDERS_MENU);
			MadedOrdersByBeginingDate.setMenu(MADED_ORDERS_MENU);
			MadedOrdersByDeadlineDate.setMenu(MADED_ORDERS_MENU);
			MadedOrdersByPrice.setMenu(MADED_ORDERS_MENU);
			
			//create sortmadingordersby_menu
			sortMadingOrdersMenu.add(new MadingOrdersByFillingDate());
			sortMadingOrdersMenu.add(new MadingOrdersByBeginingDate());
			sortMadingOrdersMenu.add(new MadingOrdersByDeadlineDate());
			sortMadingOrdersMenu.add(new MadingOrdersByPrice());
			sortMadingOrdersMenu.add(backInAllOrderMenu);
			MADING_ORDERS_MENU.setMenu(sortMadingOrdersMenu);
			ListMadingOrders.setMenu(MADING_ORDERS_MENU);
			MadingOrdersByFillingDate.setMenu(MADING_ORDERS_MENU);
			MadingOrdersByBeginingDate.setMenu(MADING_ORDERS_MENU);
			MadingOrdersByDeadlineDate.setMenu(MADING_ORDERS_MENU);
			MadingOrdersByPrice.setMenu(MADING_ORDERS_MENU);
						
			
			//create getorderlistmenu
			getOrderListMenu.add(new ListAllOrders());
			getOrderListMenu.add(new ListDeletedOrders());
			getOrderListMenu.add(new ListCanceledOrders());
			getOrderListMenu.add(new ListMadedOrders());
			getOrderListMenu.add(new ListMadingOrders());
			getOrderListMenu.add(backInOrderMenu);
			ORDER_LIST_MENU.setMenu(getOrderListMenu);
			OrdersList.setMenu(ORDER_LIST_MENU);
			
			
			//create markordermenu
			markOrderMenu.add(new OrderDeletedStatus());
			markOrderMenu.add(new OrderCanceledStatus());
			markOrderMenu.add(new OrderMadedStatus());
			markOrderMenu.add(backInOrderMenu);
			ORDER_STATUS_MENU.setMenu(markOrderMenu);
			MarkerOrder.setMenu(ORDER_STATUS_MENU);
			OrderDeletedStatus.setMenu(ORDER_STATUS_MENU);
			OrderCanceledStatus.setMenu(ORDER_STATUS_MENU);
			OrderMadedStatus.setMenu(ORDER_STATUS_MENU);
		//create order menu
		orderMenu.add(new OrdersList());
		orderMenu.add(new OrderByMaster());
		orderMenu.add(new MarkerOrder());
		orderMenu.add(new CreatorOrder());
		orderMenu.add(new OffsetOrdersDeadlineDate());
		orderMenu.add(backInMainMenu);
		ORDER_MENU.setMenu(orderMenu);
		WorkerWithOrder.setMenu(ORDER_MENU);
		OrderByMaster.setSubmenu(ORDER_MENU);
		CreatorOrder.setSubmenu(ORDER_MENU);
		OffsetOrdersDeadlineDate.setMenu(ORDER_MENU);
		
		//create resavedata menu
		ResaveData.setSubmenu(MainMenu.MAINMENU);
		
		// create main menu
				mainMenu.add(new WorkerWithGarage());
				mainMenu.add(new WorkerWithMaster());
				mainMenu.add(new WorkerWithOrder());
				mainMenu.add(new ResaveData());
				mainMenu.add(new ExitItem());
				MainMenu.MAINMENU.setMenu(mainMenu);

		
	}
}
